extends Node

# 创建牌堆类
class_name Deck

var originalDeck : Array
var currentDeck : Array

# 构造函数，初始化牌库
func _init():
	originalDeck = [] #原始牌库
	currentDeck = [] #当前牌库
	initializeDeck()

# 初始化牌库
func initializeDeck():
	var mahjongTypes = [
		"wan_1", "wan_2", "wan_3", "wan_4", "wan_5", "wan_6", "wan_7", "wan_8", "wan_9",  # 一万到九万
		"tong_1", "tong_2", "tong_3", "tong_4", "tong_5", "tong_6", "tong_7", "tong_8", "tong_9",  # 一筒到九筒
		"tiao_1", "tiao_2", "tiao_3", "tiao_4", "tiao_5", "tiao_6", "tiao_7", "tiao_8", "tiao_9",  # 一条到九条
		"dong_1", "nan_1", "xi_1", "bei_1", "hongzhong_1", "facai_1", "baiban_1"  # 东风 南风 西风 北风 红中 发财 白板
	]

	var idCounter = 1
	for type in mahjongTypes:
		for i in range(4):  # 每种4张
			var card_id = type + "_" + str(idCounter)
			self.originalDeck.append(card_id)
			self.currentDeck.append(card_id)
			idCounter += 1

	self.currentDeck.shuffle()  # 打乱牌堆

# 获取当前回合的牌库
func getDeck() -> Array:
	return self.currentDeck

# 更新牌库（例如添加牌、删除牌等）
func updateDeck(card_id: String, count: int):
	for i in range(count):
		self.currentDeck.append(card_id)  # 向牌库中添加牌
	self.currentDeck.shuffle()  # 更新牌库时重新打乱

# 重置牌库为初始状态
func resetDeck():
	self.currentDeck = self.originalDeck.duplicate(true)  # 重置为原始牌库
	self.currentDeck.shuffle()  # 打乱牌堆
	print("牌库已重置")
